<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/18 0018
 * Time: 13:04
 */
namespace Admin\Model;

use Think\Model;
class CategoryModel extends Model{
    function all_category(){
        $Category = M('Category');
        $categories = $Category->where('parent_id = 0')->order('sort_order')->select();
        foreach ($categories as &$category){
            $children = $Category->where("parent_id = $category[id]")->select();
            $category['children'] = $children;
        }
        return $categories;
    }
}